from selenium import webdriver
from selenium.webdriver.common.by import By
from time import sleep

op = webdriver.ChromeOptions()
op.add_experimental_option('excludeSwitches', ['enable-automation'])
op.add_experimental_option('useAutomationExtension', False)
driver = webdriver.Chrome(options=op)

driver.get(r"http://news.baidu.com/")

aList = driver.find_elements(By.CSS_SELECTOR, "div#localnews-zixun>ul>li")
print(len(aList))

for i in aList:
    content = i.text
    i.click()
    sleep(2)
    all_handles = driver.window_handles
    driver.switch_to.window(all_handles[1])

    print(driver.title)
    title = driver.title
    if len(content) > 10:
       content = content[0:10]
    assert content in title
    driver.close()

    driver.switch_to.window(all_handles[0])
    sleep(2)


driver.quit()